package com.abocode.jfaster.web.common.manager;

import com.abocode.jfaster.core.util.ContextHolderUtils;
import com.abocode.jfaster.web.system.bean.ClientBean;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * 对在线用户的管理
 *
 * @author JueYue
 * @version 1.0
 * @date 2013-9-28
 */
public class ClientManager {
    private static ClientManager instance = new ClientManager();

    private ClientManager() {
    }

    public static ClientManager getInstance() {
        return instance;
    }

    private Map<String, ClientBean> map = new HashMap<String, ClientBean>();

    /**
     * @param sessionId
     * @param client
     */
    public void addClinet(String sessionId, ClientBean client) {
        map.put(sessionId, client);
    }

    /**
     * sessionId
     */
    public void removeClinet(String sessionId) {
        map.remove(sessionId);
    }

    /**
     * @param sessionId
     * @return
     */
    public ClientBean getClient(String sessionId) {
        return map.get(sessionId);
    }

    /**
     * @return
     */
    public ClientBean getClient() {
        return map.get(ContextHolderUtils.getSession().getId());
    }

    /**
     * @return
     */
    public Collection<ClientBean> getAllClient() {
        return map.values();
    }
}
